package com.education.mymediaplayer.ui;

import android.net.Uri;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.education.mymediaplayer.R;
import com.education.mymediaplayer.dao.NewsMediaInfo;
import com.facebook.drawee.view.SimpleDraweeView;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by zhonghang on 16/6/22.
 */

public class NewsMediaAdapter extends BaseAdapter {
    private List<NewsMediaInfo.T1457069041911Bean> mInfoList;
    private LayoutInflater mInflater;

    public NewsMediaAdapter(LayoutInflater inflater, List<NewsMediaInfo.T1457069041911Bean> list) {
        mInflater = inflater;
        mInfoList = list;
    }

    @Override
    public int getCount() {
        return mInfoList.size();
    }

    @Override
    public Object getItem(int position) {
        return position;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder vh = null;
        if (convertView == null) {
            convertView = mInflater.inflate(R.layout.item_news_media, null);
            vh = new ViewHolder(convertView);
            convertView.setTag(vh);
        } else {
            vh = (ViewHolder) convertView.getTag();
        }
        NewsMediaInfo.T1457069041911Bean info = mInfoList.get(position);
        vh.draweeviewCover.setImageURI(Uri.parse(info.getCover()));
        vh.draweeviewAuthor.setImageURI(Uri.parse(info.getTopicImg()));
        vh.textviewAuthor.setText(info.getTopicName());
        vh.textviewTitle.setText(info.getTitle());
        return convertView;
    }


    class ViewHolder {
        @BindView(R.id.draweeview_cover)
        SimpleDraweeView draweeviewCover;
        @BindView(R.id.draweeview_author)
        SimpleDraweeView draweeviewAuthor;
        @BindView(R.id.textview_author)
        TextView textviewAuthor;
        @BindView(R.id.imageview_share)
        ImageView imageviewShare;
        @BindView(R.id.imageview_comments)
        ImageView imageviewComments;
        @BindView(R.id.textview_title)
        TextView textviewTitle;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
